import { defineStore } from 'pinia'
import { menu, permission } from "../api/module/user";
import {editmenu} from "../library/treeUtil";
export const useUserStore = defineStore({
  id: 'user',
  state: () => {
    return {
      token: '',
      expires_in:0,
      islogin:false,
      userInfo: {name:"",userid:"",orname:"",orgid:"",account:"",picture:"",isLogin:"",community:"",orgname:"",role:"",phone:""},
      permissions: [],
      menus: [],
    }
  },
  actions: {
    async loadMenus(){
      const resp = await menu() as any;
      if (resp.success) {
        console.log(resp.data);
        this.menus = editmenu(resp.data);
      }
      
    },
    async loadPermissions(){
      // const { data, code } = await permission();
      // if(code == 200) {
      //   this.permissions = data;
      // }
    }
  },
  persist: {
    storage: localStorage,
    paths: ['token',"islogin", 'userInfo', 'permissions', 'menus' ,'expires_in'],
  }
})